{% extends "AcmeCommonBundle::layout.html.twig" %}

{% block title %}用户管理{% endblock %}

{% block body %}
<script>
$(function(){
	// list user
	$('.btn.list-submit').click(function() {
		$.post("{{ path('AcmeUserBundle_UserList') }}", $('#{{ form.vars.id }}').serialize(),
		function (html) {
			$('div.list-user').html(html);
			$('.btn.list-submit').button('reset');
		}, "html");
	});

	// create user
	$('.btn.create-user').click(function() {
		$('.modal.create-user').modal({ keyboard: false }, 'show');
	});
	$('.btn.create-submit').click(function() {
		$.post("{{ path('AcmeUserBundle_UserEdit') }}", $('.modal.create-user form').serialize(),
		function (data) {
			if (data == 'success') {
				$('.btn.create-submit').button('reset');
			}
		});
	});
});
{% render "AcmeCommonBundle:University:jsUniversityGenerator" %}
</script>

<form class="form-horizontal" id="{{ form.vars.id }}" {{ form_enctype(form) }}>
	<div class="row">
		<div class="span6">
			<fieldset>
			<legend>账户信息</legend>
			{% if is_granted('ROLE_SUPER_ADMIN') %}
				{{ form_row(form.userCategory) }}
			{% endif %}
				{{ form_row(form.userStatus) }}
				{{ form_row(form.emailStatus) }}
				{{ form_row(form.flag) }}
			</fieldset>
		</div>
		<div class="span6">
			<fieldset>
			<legend>详细信息</legend>
			{% if is_granted('ROLE_SUPER_ADMIN') %}
				{{ form_row(form.university) }}
			{% endif %}
			</fieldset>
		</div>
	</div>
	
	<input class="btn btn-primary create-user" type="button" value="添加新用户" />
	<input class="btn list-submit" autocomplete="off" type="button" data-loading-text="查询中..." onclick="$(this).button('loading');" value="查询" />
	{{ form_rest(form) }}
</form>

<div class="modal hide create-user">
	<div class="modal-header">
		<a class="close" data-dismiss="modal">×</a>
		<h3>添加新用户</h3>
	</div>
    <div class="modal-body">
    {% render "AcmeUserBundle:UserCRUD:create" %}
    </div>
    <div class="modal-footer">
	    <a href="#" class="btn" data-dismiss="modal">关闭</a>
	    <input class="btn btn-primary create-submit" autocomplete="off" type="button" data-loading-text="保存中..." onclick="$(this).button('loading');" value="保存" />
	    <!-- <a href="#" class="btn btn-primary" data-dismiss="modal">选择</a> -->
    </div>
</div>

<div class="list-user"></div>

{% endblock %}